package Code.Objects.Characters.Player.Weapons.Ranged.Energy.Laser;

import org.jrabbit.base.graphics.transforms.Vector2d;
import org.jrabbit.base.input.MouseHandler;
import org.jrabbit.standard.game.graphics.skins.image.ImageSkin;
import org.newdawn.slick.Color;

import Code.Objects.Characters.Player.Player;
import Code.Objects.Characters.Player.Skins.Weapons.PlayerMachineGunSkin;
import Code.Objects.Characters.Player.Weapons.Ranged.Energy.EnergyWeapon;
import Code.Objects.Effects.Lasers.Player.PlayerLaser;

public class TestLaserRifle extends EnergyWeapon
{
	private PlayerLaser laser;
	private boolean firing;
	private float minDps;
	private float dpsGain;
	private float maxRange;

	public TestLaserRifle(Player p)
	{
		super(new PlayerMachineGunSkin(), p);
		icon = new ImageSkin("Resources/Images/GUI/Game/Weapon Selection/Icons/Machine Gun.png");
		offset = 40;
		cameraModePreference = 2;
		
		minDps = 20;
		dpsGain = 200;
		maxRange = 1500;
	}
	
	public void calculateLaser(Vector2d target)
	{
		float dist = (float) target.distanceTo(owner.location());
		dist = dist > maxRange ? maxRange : dist;
		float dps = ((1f - (dist / maxRange)) * dpsGain) + minDps;
		laser.setDamage(dps);
		laser.declareLaser(owner.location().x(), owner.location().y(), rotation.angle(), 60, dist);
	}

	
	public void updateWeapon(double time)
	{
		if(MouseHandler.isButtonDown(0))
		{
			if(!firing)
			{
				laser = new PlayerLaser("Resources/Images/Effects/Lasers/Laser Skin 3.png", minDps);
				laser.color().set(Color.orange);
				owner.getWorld().addEffect(laser, "Lasers");
				firing = true;
			}
			calculateLaser(MouseHandler.location(false));
		}
		else if(firing)
		{
			firing = false;
			owner.getWorld().removeEffect(laser);
		}
	}
}